import sys
import re

headName = sys.argv[1]
codeType = sys.argv[2]
func = sys.argv[3]
reverse = sys.argv[4]

if headName==None:
    print("python3 generate.py [headfile] [type] [func] [reverse flag]")

output = 'switch (exp)\n{\n'

f = open(headName)
line = f.readline()
while line: 
    # find type
    if re.search(codeType, line) != None:
        start,end = re.search(codeType, line).span()
        varName = line[end+1:]
        for index in range(len(varName)):
            if varName[index] == ' ' or varName[index] == '[':
                varName=varName[:index]
                print(varName)
                if(reverse==None):
                    if(func!='return'):
                        output+='case \"'+varName+'\":\n\t'+func+'('+varName+');\n\tbreak;\n\n'
                    else:
                        output+='case \"'+varName+'\":\n\t'+func+' '+varName+';\n\tbreak;\n\n'
                    break
                else:
                    if(func!='return'):
                        output+='case \"'+varName+'\":\n\t'+func+'('+varName+');\n\tbreak;\n\n'
                    else:
                        output+='case \"'+varName+'\":\n\t'+func+' '+varName+';\n\tbreak;\n\n'
                    break

    line = f.readline() 
 
f.close()

output += 'default:\n\tbreak;\n}'
print(output)